<template>
  <transition name="slide-fade">
    <div v-if="show">
      <div class="mark"></div>
      <div class="box">
        <div class="header">
          <span class="title">标题</span>
          <span class="close" @click="cancel">×</span>
        </div>
        <div class="content">
          {{ content }}
        </div>
        <div class="option">
          <div class="btn" @click="comfirm">确定</div>
          <div class="btn" @click="cancel">取消</div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default{
  data() {
    return {
      show: false,
      content: '',
    }
  },
  methods: {
    showAlert(content) {
      this.show = true
      this.content = content
      console.log('触发了show方法')
    },
    comfirm() {
      this.show = false
    },
    cancel() {
      this.show = false
    },
  },
}
</script>

<style scoped>
.mark{
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.box{
  background-color: white;
  width: 300px;
  border: 1px solid #ccc;
  border-radius: 5px;
  position: absolute;
  left: 50%;
  margin-left: -150px;
  top: 30%;
}
.header{
  padding: 10px;
  border-bottom: 1px solid #ccc;
}
.close{
  float: right;
  cursor: pointer;
  user-select: none;
}
.content{
  padding: 10px;
  user-select: none;
}
.option{
  text-align: right;
  padding: 10px;;
}
.btn{
  display: inline-block;
  background-color: #3178a0;
  color: white;
  padding: 3px 6px;
  border-radius: 3px;
  user-select: none;
  transition: .2s;
}
.btn:active{
  background-color: rgba(49, 120, 160, 0.8);
}


</style>
